package runesim.node.test;

import java.util.Map;
import org.apache.mina.common.IoSession;
import runesim.node.model.Player;
import runesim.node.net.Packet;
import runesim.node.packethandler.PacketHandler;
import runesim.node.util.Logger;

public class DebuggingPacketHandler implements PacketHandler {
	
	private Map<Integer, String> packetNames;
	
	/**
	 * Creates a new DebuggingPacketHandler.
	 * 
	 * @param packetNames
	 *            A map containing packet IDs and names of packets.
	 */
	public DebuggingPacketHandler(Map<Integer, String> packetNames) {
		this.packetNames = packetNames;
	}
	
	public void handlePacket(Packet p, IoSession session) {
		String username = ((Player) session.getAttachment()).getUsername();
		Logger.log("[" + username + "] recv: " + p + " (" + packetNames.get(p.getId()) + ")");
	}
}